package com.ham.mud.commands;

import com.ham.mud.Colors;
import com.ham.mud.ServerConnection;
import com.ham.mud.commands.skills.Skill;

import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * Created by hlucas on Jun 30, 2011 at 11:39:55 AM
 */
public class SkillsCommand extends PlayerCommand {
    @Override
    public void execute(ServerConnection connection, String[] params) {
        connection.printStart("Your skills:");
        connection.println(" -------------------------------------------");
        int playerLevel = connection.getPlayer().getLevel();
        Map<Integer, List<Skill>> potentialSkills = connection.getPlayer().getMudClass().getSkills();
        Set<Integer> keys = potentialSkills.keySet();
        for(Integer key : keys) {
            String active = "Novice";
            if(key > playerLevel) {
                active = "------";
            }

            String levelString = "|   Level " + key + ":  ";
            StringBuilder sb = new StringBuilder();
            sb.append("|");
            int length = levelString.length();
            for(int i = 1; i < length; i++) {
                sb.append(" ");
            }
            String bufferString = sb.toString();
            List<Skill> skills = potentialSkills.get(key);
            boolean isFirst = true;
            for(Skill skill : skills) {
                if(isFirst) {
                    connection.println(levelString + skill.getName() + Colors.getSpaces(20, skill.getName()) + active + Colors.getSpaces(10, active) + "|");
                    isFirst = false;
                } else {
                    connection.println(bufferString + skill.getName() + Colors.getSpaces(20, skill.getName()) + active + Colors.getSpaces(10, active) + "|");
                }
            }
        }
        connection.println(" -------------------------------------------");
        connection.printEnd();
    }

    @Override
    protected String getCommandName() {
        return "skills";
    }
}
